<?php
dl('php_pdo_sqlite.dll');

    //open the database
	$db = createDB();
	addToDB($db,"a","b",1);
	addToDB($db,"d",NULL,1);
	addToDB($db,"g","b",1);
	addToDB($db,"b",NULL,1);


    $result = searchForUsernames($db,"b");
    foreach($result as $row)
    {
      print "<tr><td>".$row['Id']."</td>\n";
      print "<td>".$row['username']."</td>\n";
      print "<td>".$row['password']."</td>\n";
      print "<td>".$row['groupID']."</td></tr>\n";
    }
    print "</table>";

    $db = NULL;
  

  
  function createDB()
  {
      $db = new PDO('sqlite:AdminDB_PDO.sqlite');
      $db->exec("CREATE TABLE IF NOT EXISTS AdminDB (_id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL, password TEXT NOT NULL, groupID INTEGER)");    
	  return $db;	
   }
  function addToDB($db,$user,$pw,$id)
  {
		$db->exec("INSERT INTO AdminDB (username, password, groupID) VALUES ('$user', '$pw', '$id');");
  }
  function searchForUsernames($db, $un)
  {
        $result = $db->query("SELECT * FROM AdminDB WHERE username = '$un'");
		return $result;
  }
  function searchForPassword($db, $pw)
  {
        $result = $db->query("SELECT * FROM AdminDB WHERE password = '$pw'");
		return $result;
  }
  function searchForGIDs($db, $gid)
  {
        $result = $db->query("SELECT * FROM AdminDB WHERE groupID = '$gid'");
		return $result;
  }
  
  
?>